import jieba
from pyecharts import options as opts
from pyecharts.charts import WordCloud
with open('政府工作报告.txt','r') as file:
    text=file.read()
words=jieba.lcut(text)
words_k={}
for w in words:
    if len(w)>1:
        words_k[w]=words_k.get(w,0)+1
sorted_words=dict(sorted(words_k.items(),key=lambda item:item[1], reverse=True))
print(sorted_words)
wordCloud=WordCloud(init_opts=opts.InitOpts(page_title='词云图'))
wordCloud.add(series_name='',data_pair=words_k.items(),
              word_size_range=[20,60],shape='diamond')
wordCloud.set_global_opts(
    title_opts=opts.TitleOpts(
        title='政府工作报告词云图',
        pos_left='center'),
    legend_opts=opts.LegendOpts(is_show=False)
)
wordCloud.render('词云图.html')